package com.qzxl.conntext.utils;

import com.alibaba.fastjson.JSONObject;

import java.io.*;

/**
 * @Auther: jintianyun
 * @Date: 2020/9/9 14:00
 * @Description:
 */
public class ReadJson {
    /**
     * 读取文件中的json
     *
     * @param path 文件路径
     * @return
     */
    public static JSONObject readJson(String path) {
        StringBuffer strbuffer = new StringBuffer();
        File myFile = new File(path);
        if (!myFile.exists()) {
            // 路径错误的情况下
            System.err.println("Can't Find " + path);
        }
        try {
            FileInputStream fis = new FileInputStream(path);
            InputStreamReader inputStreamReader = new InputStreamReader(fis, "UTF-8");
            BufferedReader in = new BufferedReader(inputStreamReader);

            String str;
            while ((str = in.readLine()) != null) {
                strbuffer.append(str); // new String(str,"UTF-8")
            }
            in.close();
        } catch (IOException e) {
            e.getStackTrace();
        }
        //  ("读取文件结束util");
        JSONObject jj = JSONObject.parseObject(strbuffer.toString());
        return jj;
    }
}
